package com.glory.cqaospda.viewmodel

import com.glory.cqaospda.base.Constant
import com.glory.cqaospda.model.TaskRepository
import com.glory.mvvmnet.base.BaseViewModel
import com.glory.mvvmnet.entity.CallObserveBean
import com.glory.mvvmnet.entity.ToastMessageBean
import com.google.gson.JsonObject

class SiteModel:BaseViewModel() {

    private val repository by lazy { TaskRepository() }

    fun defaultRunLotHis(StepName: String,Action: String,LotId: String,EqpID: String) {
        val map = JsonObject()
        map.addProperty("LotNo", LotId)
        map.addProperty("Action", Action)
        map.addProperty("StepName", StepName)
        map.addProperty("EquipmentName", Constant.eqpid)
        map.addProperty("passNumBer", "")
        launchOnlyResult({
            val defaultLotInfo =
                repository.defaultRunLotHis(map,"EMS_RunLotHis")
            defUI.callObserve.value = CallObserveBean(3,defaultLotInfo)

        })
    }

    fun defaultLotInfo(lotID: String,isView:Boolean) {
        val map = JsonObject()
        map.addProperty("Lotid", lotID)
        launchOnlyResult({
            val defaultLotInfo =
                repository.defaultLotInfo(map,"EMS_GetLotInfo")
            if ("Y".equals(defaultLotInfo.mIsResidue)){
                if (!isView){
                    defUI.toastEvent.value = ToastMessageBean("当前批次为尾料",true)
                }else{
                    defUI.callObserve.value = CallObserveBean(1,defaultLotInfo)
                }
            }else{
                if (isView){
                    defUI.toastEvent.value = ToastMessageBean("当前批次为主料",true)
                }else{
                    defUI.callObserve.value = CallObserveBean(1,defaultLotInfo)
                }
            }

        })
    }

    fun defaultEqpInfo(eqpID: String) {
        val map = JsonObject()
        map.addProperty("EqpId", eqpID)
        launchOnlyResult({
            val defaultEqpInfo =
                repository.defaultEqpInfo(map,"EMS_GetEqpInfo")
            defUI.callObserve.value = CallObserveBean(2,defaultEqpInfo)

        })
    }

}